home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
asmutil
/
a86v400.zip
/
A09.DOC
< prev
next >
Wrap
Text File
|
1994-12-21
|
26KB
|
608 lines
CHAPTER 9 DIRECTIVES IN A86
Segments in A86
The following discussion applies when A86 is assembling a .COM
See the next chapter for the discussion of segmentation for .OBJ
files.
A86 views the 86 computer's memory space as having two parts: The
first part is the program, whose contents are the object bytes
generated by A86 during its assembly of the source. A86 calls
this area the CODE SEGMENT. The second part is the data area,
whose contents are generated by the program after it starts
running. A86 calls this area the DATA SEGMENT.
Please note well that the only difference between the CODE and
DATA segments is whether the contents are generated by the
program or the assembler. The names CODE and DATA suggest that
program code is placed in the CODE segment, and data structures
go in the DATA segment. This is mostly true, but there are
exceptions. For example, there are many data structures whose
contents are determined by the assembler: pointer tables, arrays
of pre-defined constants, etc. These tables are assembled in the
CODE segment.
In general, you will want to begin your program with the
directive DATA SEGMENT, followed by all your program variables
and uninitialized data structures, using the directives DB, DW,
and STRUC. If you do not give an ORG directive, A86 will begin
the allocation immediately following the end of the .COM program.
You can end the DATA SEGMENT allocation lines with the DATA ENDS
directive, followed by the program code itself. A short program
illustrating this suggested usage follows:
DATA SEGMENT
ANSWER_BYTE DB ?
CALL_COUNT DW ?
CODE SEGMENT
JMP MAIN
TRAN_TABLE:
DB 16,3,56,23,0,9,12,7
MAIN:
MOV BX,TRAN_TABLE
XLATB
MOV ANSWER_BYTE,AL
INC CALL_COUNT
RET
A86 allows you to intersperse CODE SEGMENTs and DATA SEGMENTs
throughout your program; but in general it is best to put all
your DATA SEGMENT declarations at the top of your program, to
avoid problems with forward referencing.
9-2
CODE ENDS and DATA ENDS Statements
For compatibility with Intel/IBM assemblers, A86 provides the
CODE ENDS and DATA ENDS statements. The CODE ENDS statement is
ignored; we assume that you have not nested a CODE segment inside
a DATA segment. The DATA ENDS statement is equivalent to a CODE
SEGMENT statement.
The ORG Directive
Syntax: ORG address
ORG moves the output pointer (the location counter at which
assembly is currently taking place within the current segment) to
the value of the operand. In the CODE segment, the operand
should be an absolute constant, or an expression evaluating to an
absolute, non-forward-referenced constant. In the DATA segment,
the operand may be a forward reference or an expression
containing one or more forward references. All symbols in the
segment will be resolved when the forward references to the ORG
operand are all resolved.
There is a special side effect to ORG when it is used in the CODE
segment. If you begin your code segment with ORG 0, then A86
knows that you are not assembling a .COM program; but are instead
assembling a code segment to be used in some other context
(examples: programming a ROM, or assembling a procedure for older
versions of Turbo Pascal). The output file will start at 0, not
0100 as in a .COM file; and the default extension for the output
file will be .BIN, not .COM. However, if you later issue an ORG
0100 directive, the default will revert back to .COM.
Other than in the above example, you should not in general issue
an ORG within the CODE segment that would lower the value of the
output pointer. This is because you thereby put yourself in
danger of losing part of your assembled program. If you
re-assemble over space you have already assembled, you will
clobber the previously-assembled code. Also, be aware that the
size of the output program file is determined by the value of the
code segment output pointer when the program stops. If you ORG
to a lower value at the end of your program, the output program
file will be truncated to the lower-value address.
Again, almost no program producing a .COM file will need any ORG
directive in the code segment. There is an implied ORG 0100 at
the start of the program. You just start coding instructions,
and the assembler will put them in the right place.
9-3
The EVEN Directive
Syntax: EVEN constant
The EVEN directive coerces the current output pointer to a value
which is an exact multiple of the operand. If no operand is
given, a value of 2 is assumed. In a DATA SEGMENT or STRUC, it
does so by adding to the current output pointer if necessary. In
a code segment, it outputs an appropriate number of NOP
instruction bytes. EVEN is most often used in data segments,
before a sequence of DW directives. Machines beyond the original
8088 fetch words more quickly when they are aligned onto even
addresses; so the EVEN directive insures that your program will
have the faster access to those DW's that follow it. Also useful
are EVEN 4 for doubleword alignment, and EVEN 16 for paragraph
alignment. Be aware, though, that if you use the EVEN directive
in .OBJ mode, the containing SEGMENT directive should have an
alignment type at least as great as your EVEN operand, to achieve
the desired alignment at its final memory location.
Data Allocation Using DB, DW, DD, DQ, and DT
The 86 computer family supports the three fundamental data types
BYTE, WORD, and DWORD. A byte is eight bits, a word is 16 bits
(2 bytes), and a doubleword is 32 bits (4 bytes). In addition,
the 87 floating point processor manipulates 8-byte quantities,
which we call Q-words, and 10-byte quantities, which we call
T-bytes. The A86 data allocation statement is used to specify
the bytes, words, doublewords, Q-words, and T-bytes which your
program will use as data. The syntax for the data allocation
statement is as follows:
(optional var-name) DB (list of values)
(optional var-name) DW (list of values)
(optional var-name) DD (list of values)
(optional var-name) DQ (list of values)
(optional var-name) DT (list of values)
The variable name, if present, causes that name to be entered
into the symbol table as a memory variable with type BYTE (for
DB), WORD (for DW), DWORD (for DD), QWORD (for DQ), or TBYTE (for
DT). The variable name should NOT have a colon after it, unless
you wish the name to be a label (instructions referring to it
will interpret the label as the constant pointer to the memory
location, not its contents).
The DB statement is used to reserve bytes of storage; DW is used
to reserve words. The list of values to the right of the DB or
DW serves two purposes. It specifies how many bytes or words are
allocated by the statement, as well as what their initial values
should be. The list of values may contain a single value or more
than one, separated by commas. The list can even be missing;
meaning that we wish to define a byte or word variable at the
same location as the next variable.
9-4
If the data initialization is in the DATA segment, the values
given are ignored, except as place markers to reserve the
appropriate number of units of storage. The use of "?", which in
.COM mode is a synonym for zero, is recommended in this context
to emphasize the lack of actual memory initialization. When A86
is assembling .OBJ files, the ?-initialization will cause a break
in the segment (unless ? is embedded in a nested DUP containing
non-? terms, in which case it is a synonym for zero).
A special value which can be used in data initializations is the
DUP construct, which allows the allocation and/or initialization
of blocks of data. The expression n DUP x is equivalent to a
list with x repeated n times. "x" can be either a single value,
a list of values, or another DUP construct nested inside the
first one. The nested D